﻿Imports System.Data.SqlClient
Imports QuanLyBanChau.PhieuNhap

Public Class PhieuNhap_dao
    Public Shared Sub insertPhieuNhapdao(ByVal PhieuNhap As PhieuNhap)
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim para(7) As SqlParameter
        conn = dataprovider.Connection()
        cmd = New SqlCommand("insert_PhieuNhap", conn)
        cmd.CommandType = CommandType.StoredProcedure
        para(0) = New SqlParameter(" @Maphieunhap", SqlDbType.VarChar, 10)
        para(0).Value = PhieuNhap.Maphieunhap
        cmd.Parameters.Add(para(0))
        para(1) = New SqlParameter(" @Machau", SqlDbType.VarChar, 10)
        para(1).Value = PhieuNhap.Machau
        cmd.Parameters.Add(para(1))

        para(2) = New SqlParameter(" @Ngaynhap", SqlDbType.DateTime)
        para(2).Value = PhieuNhap.Ngaynhap
        cmd.Parameters.Add(para(2))

        para(3) = New SqlParameter(" @Soluongnhap", SqlDbType.Int)
        para(3).Value = PhieuNhap.Soluongnhap
        cmd.Parameters.Add(para(3))


        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
    End Sub


    Public Shared Sub DeletePhieuNhapdao(ByVal Maphieunhap)
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim para(1) As SqlParameter
        conn = dataprovider.Connection()
        cmd = New SqlCommand("Delete_PhieuNhap", conn)
        cmd.CommandType = CommandType.StoredProcedure
        para(1) = New SqlParameter(" @Maphieunhap", SqlDbType.VarChar, 10)
        para(1).Value = Maphieunhap
        cmd.Parameters.Add(para(1))
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
    End Sub
    Public Shared Function Get_PhieuNhapdao()
        Dim conn As SqlConnection
        conn = dataprovider.Connection()
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable
        da.SelectCommand = New SqlCommand
        da.SelectCommand.Connection = conn
        da.SelectCommand.CommandType = CommandType.StoredProcedure
        da.SelectCommand.CommandText = "Get_PhieuNhap"
        da.Fill(dt)
        Return dt
    End Function

    Public Shared Sub UpdatePhieuNhapdao(ByVal PhieuNhap As PhieuNhap)
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim para(7) As SqlParameter
        conn = dataprovider.Connection()
        cmd = New SqlCommand("Update_PhieuNhap", conn)
        cmd.CommandType = CommandType.StoredProcedure
        para(0) = New SqlParameter(" @Maphieunhap", SqlDbType.VarChar, 10)
        para(0).Value = PhieuNhap.Maphieunhap
        cmd.Parameters.Add(para(0))
        para(1) = New SqlParameter(" @Machau", SqlDbType.VarChar, 10)
        para(1).Value = PhieuNhap.Machau
        cmd.Parameters.Add(para(1))

        para(2) = New SqlParameter(" @Ngaynhap", SqlDbType.DateTime)
        para(2).Value = PhieuNhap.Ngaynhap
        cmd.Parameters.Add(para(2))

        para(3) = New SqlParameter(" @Soluongnhap", SqlDbType.Int)
        para(3).Value = PhieuNhap.Soluongnhap
        cmd.Parameters.Add(para(3))


        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
    End Sub

End Class
